<template>
  <div v-loading="loading">
    <div class="header-search cad-box">
      <el-select
        v-model="searchValue.type"
        placeholder="请选择"
        style="width: 20%; margin: 0px 10px"
      >
        <el-option
          v-for="item in options1"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-date-picker
        v-model="searchValue.createTime"
        type="daterange"
        value-format="yyyy-MM-dd"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
      <el-button
        type="primary"
        style="margin: 0px 10px"
        @click="handleTuoGovInstitutionalReportList"
      >搜 索</el-button>
    </div>

    <div class="content-table cad-box">
      <el-button
        type="primary"
        style="margin: 0px 10px"
        @click="handleInfo({}, 'add')"
      >新增</el-button>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="date" label="汇报类型" align="center">
          <template slot-scope="scope">
            {{
              options1.find((item) => item.value === scope.row.reportType).label
            }}
          </template>
        </el-table-column>
        <el-table-column prop="staffName" label="汇报人" align="center" />
        <el-table-column prop="createTime" label="汇报时间" align="center" />
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleInfo(scope.row, 'info')"
            >详情</el-button>
            <el-button
              type="text"
              size="small"
              @click="handleRemove(scope.row.id)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align: right">
        <el-pagination
          :current-page="pagination.pageNum"
          :page-sizes="[10, 15, 30, 50]"
          :page-size="pagination.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import {
  tuoGovInstitutionalReportList,
  tuoGovInstitutionalReportRemove
} from './api'
export default {
  data () {
    return {
      searchValue: {
        type: '',
        createTime: ''
      },
      options1: [
        {
          value: '',
          label: '全部'
        },
        {
          value: 0,
          label: '月报'
        },
        {
          value: 1,
          label: '季报'
        },
        {
          value: 2,
          label: '年报'
        }
      ],
      options2: [
        {
          value: 1,
          label: '安全'
        },
        {
          value: 2,
          label: '卫生'
        },
        {
          value: 3,
          label: '环境'
        }
      ],
      value1: '',
      value2: '',
      drawer: false,
      direction: 'rtl',
      infoItem: {},
      loading: false,
      tableData: [],
      pagination: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  computed: {},
  created () {
    this.handleTuoGovInstitutionalReportList()
  },
  mounted () {},
  methods: {
    handleRemove (id) {
      const ids = id
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          await tuoGovInstitutionalReportRemove(ids)
          this.handleTuoGovInstitutionalReportList()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch((err) => {
          console.log(err)
        })
    },
    async handleTuoGovInstitutionalReportList () {
      this.loading = true
      const res = await tuoGovInstitutionalReportList({
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        startTime: this.searchValue.createTime[0],
        endTime: this.searchValue.createTime[1],
        reportType: this.searchValue.type
      })
      this.loading = false
      console.log(res, 'handleTuoGovInstitutionalReportList')
      this.tableData = res.records
      this.total = Number(res.total)
    },
    handleInfo (item, type) {
      this.$router.push(`/report/addInfo?id=${item.id}&type=${type}`)
    },
    onSubmit () {},
    getTableList () {},
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.pagination.pageSize = val
      this.getTableList()
    },

    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.pagination.pageNum = val
      this.getTableList()
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-drawer__header {
  color: #000 !important;
  font-size: 18px !important;
}

.header-search {
  display: flex;
  margin-bottom: 30px;

  .select-box {
    width: 20%;
    margin: 0 20px;
  }
}

.drawer_box {
  width: 100%;
  padding: 0px 50px;
  .drawer_item {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
    padding: 10px;
  }
}
</style>
